<template>
    <div class="app-container">
        <el-button class="handleTap" @click="back">返回</el-button>
        <el-button type="primary" :loading='loading' @click="submitForm(pageConfig.pageeModel.name)">保 存</el-button>
        <div style="display: inline;margin-left: 40px;font-weight: bold;">{{pageConfig.title}}页面配置</div>
        <createOrder v-if="pageConfig.pageeModel.name=='createOrder'" :ref="pageConfig.pageeModel.name" :formModel="pageConfig"></createOrder>
        <createOrderForStock v-if="pageConfig.pageeModel.name=='createOrderForStock'" :ref="pageConfig.pageeModel.name" :formModel="pageConfig"></createOrderForStock>
        <mine v-if="pageConfig.pageeModel.name=='mine'" :ref="pageConfig.pageeModel.name" :formModel="pageConfig"></mine>
        <authLogin v-if="pageConfig.pageeModel.name=='authLogin'" :ref="pageConfig.pageeModel.name" :formModel="pageConfig"></authLogin>
        <duoshou v-if="pageConfig.pageeModel.name=='duoshou'" :ref="pageConfig.pageeModel.name" :formModel="pageConfig"></duoshou>
        <applyAgent v-if="pageConfig.pageeModel.name=='applyAgent'" :ref="pageConfig.pageeModel.name" :formModel="pageConfig"></applyAgent>
    </div>
</template>

<script>
    import {
        updatePageConfig
    } from '@/api/interface/page.js'
    import createOrder from '@/views/interface/pageConfigList/components/createOrder'
    import createOrderForStock from '@/views/interface/pageConfigList/components/createOrderForStock'
    import mine from '@/views/interface/pageConfigList/components/mine'
    import authLogin from '@/views/interface/pageConfigList/components/authLogin'
    import duoshou from '@/views/interface/pageConfigList/components/duoshou'
    import applyAgent from './components/applyAgent.vue'
    export default {
      components: {
        createOrder,
        createOrderForStock,
        mine,
        authLogin,
        duoshou,
        applyAgent
      },
        data() {
            return {
                pageConfig: {},
                loading: false,
            }
        },
        created(){
            this.pageConfig = JSON.parse(decodeURIComponent(this.$route.query.data))
        },
        methods: {
            submitForm(formName){
                if(this.$refs[formName].validateForm()){
                    if(this.pageConfig.id){
                        this.pageConfig.pageConfigId = this.pageConfig.id
                        this.loading = true
                        updatePageConfig(this.pageConfig).then(res=>{
                            this.loading = false
                            if(res.data.code == 10000){
                                this.$message({
                                type: 'success',
                                message: '保存成功'
                                })
                            }
                        })
                    }
                }
            },
            back(){
                this.$router.back()
            }
        }
    }
</script>